< previous page page_368 next page >

Page 368
a TwoDLine object reads an older serialization, it will not find a ForeColor value. That will not make the program fail, though. It just means the object's ForeColor property is not initialized.
The serializations also provide forward compatibility. Suppose you send a new serialization with the ForeColor property to someone whose program does not support that property. When it reads the serialization, the TwoDLine object simply ignores the property it does not understand. It does not crash.
The convenience of forward and backward compatibility does come at the price of reduced error checking. If a serialization contains the property ForeColor misspelled as FireColor, the program will quietly ignore this value without telling you there is a potential problem.
Using techniques similar to those demonstrated by the TwoDLine class, you can create other objects with other properties. Example program Show2D supports a variety of object types including lines, circles, ellipses, rectangles, squares, and polygons.
Program Show2D also includes a TwoDScene class that contains references to other objects in its SceneObjects collection. This class allows the program to group objects and perform operations on all of them together. For example, the following code shows how the TwoDScene object's Draw method allows the program to draw all of the objects in the scene.
e10a6a0a59f035e870d90cca05b85fce.gif
' Draw the object on the canvas.
Private Sub TwoDObject_Draw(ByVal canvas As Object)
Dim obj As TwoDObject

    For Each obj In SceneObjects
         obj.Draw canvas
    Next obj
End Sub
The classes used by program Show2D implement the drawing properties DrawWidth, DrawStyle, ForeColor, FillStyle, and FillColor. These allow a program to create objects with different colors and drawing styles.
The objects used by program Show2D can also draw themselves into Windows metafiles. Many applications can load metafiles, so this gives you a way to export drawings into other programs. For example, you can create a scene using a Visual Basic program, save the results into a metafile, and then load the metafile into CorelDRAW! or some other drawing program.
Example program Show2D, shown in Figure 12.1, is based on the Styles program described in Chapter 1, Visual Basics. You can use the option buttons to select drawing attributes and objects. Then click and drag to draw the objects. When you have finished, use the File menu's Save 2D File command to save the picture's object serialization in a file. Use the Save Metafile command to make the objects draw themselves into a metafile.

 
< previous page page_368 next page >